package com.ktjy.ruoyidata.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.enums.BusinessType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ktjy.ruoyidata.domain.MyMeasure;
import com.ktjy.ruoyidata.service.IMyMeasureService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 计量单位Controller
 * 
 * @author t382
 * @date 2025-04-28
 */
@RestController
@RequestMapping("/ruoyidata/measure")
public class MyMeasureController extends BaseController
{
    @Autowired
    private IMyMeasureService myMeasureService;

    /**
     * 查询计量单位列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyidata:measure:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyMeasure myMeasure)
    {
        startPage();
        List<MyMeasure> list = myMeasureService.selectMyMeasureList(myMeasure);
        return getDataTable(list);
    }

    /**
     * 导出计量单位列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyidata:measure:export')")
    @Log(title = "计量单位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MyMeasure myMeasure)
    {
        List<MyMeasure> list = myMeasureService.selectMyMeasureList(myMeasure);
        ExcelUtil<MyMeasure> util = new ExcelUtil<MyMeasure>(MyMeasure.class);
        util.exportExcel(response, list, "计量单位数据");
    }

    /**
     * 获取计量单位详细信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyidata:measure:query')")
    @GetMapping(value = "/{measureId}")
    public AjaxResult getInfo(@PathVariable("measureId") Long measureId)
    {
        return success(myMeasureService.selectMyMeasureByMeasureId(measureId));
    }

    /**
     * 新增计量单位
     */
    @PreAuthorize("@ss.hasPermi('ruoyidata:measure:add')")
    @Log(title = "计量单位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyMeasure myMeasure)
    {
        return toAjax(myMeasureService.insertMyMeasure(myMeasure));
    }

    /**
     * 修改计量单位
     */
    @PreAuthorize("@ss.hasPermi('ruoyidata:measure:edit')")
    @Log(title = "计量单位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyMeasure myMeasure)
    {
        return toAjax(myMeasureService.updateMyMeasure(myMeasure));
    }

    /**
     * 删除计量单位
     */
    @PreAuthorize("@ss.hasPermi('ruoyidata:measure:remove')")
    @Log(title = "计量单位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{measureIds}")
    public AjaxResult remove(@PathVariable Long[] measureIds)
    {
        return toAjax(myMeasureService.deleteMyMeasureByMeasureIds(measureIds));
    }
}
